﻿/********************************************************************
	日期:2022/07/07
	名称:DynamicWnd
	邮箱:yunnibbd@163.com
	作者:yunni
	描述:角色信息展示页面
*********************************************************************/

using PEProtocol;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class InfoWnd : WindowRoot{
	
	#region UI_Define
	public RawImage imgChar;

	public Text txtInfo;
	public Text txtExp;
	public Image imgExpPrg;
	public Text txtPower;
	public Image imgPowerPrg;
	public Text txtJob;
	public Text txtFight;
	public Text txtHp;
	public Text txtHurt;
	public Text txtDef;

	public Transform transDetail;
	public Text detailHp;
	public Text detailAd;
	public Text detailAp;
	public Text detailAdDef;
	public Text detailApDef;
	public Text detailDodge;
	public Text detailPierce;
	public Text detailCritical;
	
	#endregion
	
	public Vector2 startPos;

	protected override void InitWnd(){
		base.InitWnd();
		RefreshUI();
		SetActive(transDetail, false);
		RegTouchEvents();
	}

	private void RegTouchEvents(){
		OnClickDown(imgChar.gameObject, (PointerEventData evt)=> {
			startPos = evt.position;
			MainCitySys.Instance.SetStartRotate();
		});
		
		OnDraw(imgChar.gameObject, (PointerEventData evt) => {
			float rotate = -(evt.position.x - startPos.x) * 0.4f;
			MainCitySys.Instance.SetPlayerRotate(rotate);
		});
	}
	
	private void RefreshUI(){
		PlayerData pd = GameRoot.Instance.PlayerData;
		SetText(txtInfo, pd.name + "LV." + pd.level);
		SetText(txtExp, pd.exp + "/" + PECommon.GetExpUpValByLevel(pd.level));
		imgExpPrg.fillAmount = pd.exp * 1.0F / PECommon.GetExpUpValByLevel(pd.level);
		SetText(txtPower, pd.power + "/" + PECommon.GetPowerLimit(pd.level));
		imgPowerPrg.fillAmount = pd.power * 1.0F / PECommon.GetPowerLimit(pd.level);
		SetText(txtJob, "暗夜刺客");
		SetText(txtFight, PECommon.GetFightByProps(pd));
		SetText(txtHp, pd.hp);
		SetText(txtHurt, pd.ad + pd.ap);
		SetText(txtDef, pd.addef + pd.apdef);
		
		SetText(detailHp, pd.hp);
		SetText(detailAd, pd.ad);
		SetText(detailAp, pd.ap);
		SetText(detailAdDef, pd.addef);
		SetText(detailApDef, pd.apdef);
		SetText(detailDodge, pd.dodge + "%");
		SetText(detailPierce, pd.pierce + "%");
		SetText(detailCritical, pd.critcal + "%");
	}

	public void ClickCloseBtn(){
		audioSvc.PlayUIMusic(Constants.UIClickBtn);
		SetWndState(false);
		MainCitySys.Instance.CloseInfoWnd();
	}

	public void ClickDetail(){
		audioSvc.PlayUIMusic(Constants.UIClickBtn);
		SetActive(transDetail);
	}
	
	public void ClickCloseDetailBtn(){
		audioSvc.PlayUIMusic(Constants.UIClickBtn);
		SetActive(transDetail, false);
	}
}
